var Router = Backbone.Router.extend({

	initialize: function(){
		this.main = new Main();
		this.login = new LoginView();
		this.currentTable = new Table();
	},

	routes: {	
		"": "login",
		"map": "paintMain",
		"table/:id": "paintTable"
	},

	login: function(){
		this.apikey = false;
		this.login.render();
	},

	paintMain: function(){
		if(this.apikey === false || typeof this.apikey === 'undefined'){
			this.navigate('', true); 
			return;
		} 
		this.main.render();
	},

	paintTable: function(id){
		if(this.apikey === false || typeof this.apikey === 'undefined'){
			this.navigate('', true); 
			return;
		} 
		
		var tableModel = this.main.getTableById(id);
		this.currentTable.render({model: tableModel});
	}
	
});

